<template>
<!-- 顶部导航栏部分 -->
  <nav class="app-navBar">
    <div class="container">
      <ul>
        <template v-if="profile.token">
          <li><a href="javascript;"> <i class="iconfont icon-user"></i> 周杰伦</a></li>
          <li><a  @click="logout()">退出登录</a></li>
        </template>
        <template v-else>
          <li><router-link to="/login">请先登录</router-link></li>
          <li><a href="javascript;">免费注册</a></li>
        </template>
        <li><a href="javascript;">我的订单</a></li>
        <li><router-link to="/member">会员中心</router-link></li>
        <li><a href="javascript;">帮助中心</a></li>
        <li><a href="javascript;">关于我们</a></li>
        <li><a href="javascript;"><i class="iconfont icon-phone"></i> 手机版</a></li>
      </ul>
    </div>
  </nav>
</template>

<script>
import { computed } from 'vue'
import { useStore } from 'vuex'
import Message from './library/Message.js'
import { useRouter } from 'vue-router'
export default {
  name: 'AppNavBar',
  setup () {
    const store = useStore()
    const profile = computed(() => {
      return store.state.user.profile
    })

    const router = useRouter()
    const logout = () => {
      store.commit('user/setUser', {})
      router.push('/login')
      store.commit('cart/setCartList', [])
      Message({ text: '退出成功', type: 'success' })
    }
    return { profile, logout }
  }
}
</script>

<style lang="less" scoped>
.app-navBar {
  background-color: #333;
  .container {
    ul {
      display: flex;
      height: 53px;
      align-items: center;
      justify-content: flex-end;
      li {
        a {
          padding: 0 15px;
          line-height: 1;
          display: inline-block;
          color: #cdcdcd;
          i {
            font-size: 14px;
          }
          &:hover {
           color: @xtxColor;
          }
        }
        ~li {
        a{
          border-left: 1px solid #cdcdcd;
        }
      }
      }

    }
  }
}
</style>
